package com.ruoyi.web.controller.ability;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysUserScan;
import com.ruoyi.system.service.ISysUserScanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 扫码记录Controller
 *
 * @author ruoyi
 * @date 2025-05-09
 */
@RestController
@RequestMapping("/system/scan")
public class SysUserScanController extends BaseController
{
    @Autowired
    private ISysUserScanService sysUserScanService;

    /**
     * 查询扫码记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:scan:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysUserScan sysUserScan)
    {
        startPage();
        List<SysUserScan> list = sysUserScanService.selectSysUserScanList(sysUserScan);
        return getDataTable(list);
    }

    /**
     * 导出扫码记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:scan:export')")
    @Log(title = "扫码记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUserScan sysUserScan)
    {
        List<SysUserScan> list = sysUserScanService.selectSysUserScanList(sysUserScan);
        ExcelUtil<SysUserScan> util = new ExcelUtil<SysUserScan>(SysUserScan.class);
        util.exportExcel(response, list, "扫码记录数据");
    }

    /**
     * 获取扫码记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:scan:query')")
    @GetMapping(value = "/{scanId}")
    public AjaxResult getInfo(@PathVariable("scanId") Long scanId)
    {
        return success(sysUserScanService.selectSysUserScanByScanId(scanId));
    }

    /**
     * 新增扫码记录
     */
    @PreAuthorize("@ss.hasPermi('system:scan:add')")
    @Log(title = "扫码记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUserScan sysUserScan)
    {
        return toAjax(sysUserScanService.insertSysUserScan(sysUserScan));
    }

    /**
     * 修改扫码记录
     */
    @PreAuthorize("@ss.hasPermi('system:scan:edit')")
    @Log(title = "扫码记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUserScan sysUserScan)
    {
        return toAjax(sysUserScanService.updateSysUserScan(sysUserScan));
    }

    /**
     * 删除扫码记录
     */
    @PreAuthorize("@ss.hasPermi('system:scan:remove')")
    @Log(title = "扫码记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scanIds}")
    public AjaxResult remove(@PathVariable Long[] scanIds)
    {
        return toAjax(sysUserScanService.deleteSysUserScanByScanIds(scanIds));
    }
}
